package com.bl.service.order;

import java.util.List;

import com.bean.Order;
import com.bl.action.Command;
import com.bl.action.customer.BeanActions;
import com.bl.service.Service;
import com.bl.util.LoggingCommandExecutor;
import com.dao.factory.DaoFactory;
import com.dao.factory.DaoFactory.FactoryType;
import com.dao.factory.StartupFactoryType;

/**
 * @author ${user}
 */
public class OrderServiceWithLogging implements Service<Order>{

    FactoryType defaultFactoryType = new StartupFactoryType().getDefaultFactoryType();
    DaoFactory daoFactory = DaoFactory.getDaoFactory(defaultFactoryType);
    BeanActions<Order> orderActions = new BeanActions<Order>(daoFactory.getOrderDao(), new OrderFactory(defaultFactoryType));
    LoggingCommandExecutor commandExecutor = new LoggingCommandExecutor();

    @Override
    public void insertToDbOneByOne(final List<Order> aObject) {
        final Command<Void> insertOrdersToDbOneByOneAction = orderActions.getInsertBeansToDbOneByOneAction(aObject);
        commandExecutor.executeCommand(insertOrdersToDbOneByOneAction, "Insert of the generated orders performed in:");
    }


    @Override
    public void insertUsingBatches(final List<Order> aOrders) {
        final Command<Void> insertOrdersUsingBatchesAction = orderActions.getInsertBeansUsingBatchesAction(aOrders);
        commandExecutor.executeCommand(insertOrdersUsingBatchesAction, "Batch Insert of the generated orders performed in: ");
    }


    @Override
    public void deleteFromDbOneByOne(final List<Order> aOrders) {
        final Command<Void> deleteOrdersFromDbOneByOneAction = orderActions.getDeleteBeansFromDbOneByOneAction(aOrders);
        commandExecutor.executeCommand(deleteOrdersFromDbOneByOneAction, "Delete * orders from DB one by one: ");
    }


    @Override
    public void deleteUsingBatches(final List<Order> aOrders) {
        final Command<Void> deleteOrdersUsingBatchesAction = orderActions.getDeleteBeansUsingBatchesAction(aOrders);
        commandExecutor.executeCommand(deleteOrdersUsingBatchesAction, "Batch Delete of the generated orders: ");
    }


    @Override
    public Order findById(final Integer id) {
        throw new RuntimeException("Not implemented yet");
    }


    @Override
    public List<Order> generateObjects(final int aNumberOfOrders) {
        final Command<List<Order>> generateOrdersAction = orderActions.getGenerateBeansAction(aNumberOfOrders);
        return commandExecutor.executeCommand(generateOrdersAction, "generated " + aNumberOfOrders + " performed in: ");
    }
}
